﻿using QInjection.Injector.Contracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QInjection.Injector
{
    internal class RuleNodeMap
    {
        private Dictionary<Node, Dictionary<Restriction, Boolean>> _map;

        internal RuleNodeMap()
        {
            _map = new Dictionary<Node, Dictionary<Restriction, bool>>();

            foreach (Node n in Enum.GetValues(typeof(Node)))
            {
                _map[n] = new Dictionary<Restriction, bool>();
                foreach (Restriction r in Enum.GetValues(typeof(Restriction)))
                {
                    (_map[n])[r] = false;
                }
            }

            (_map[Node.BinaryExpression])[Restriction.Operator] = true;
            (_map[Node.MemberAccessExpression])[Restriction.Name] = true;
            (_map[Node.MemberAccessExpression])[Restriction.NameRegex] = true;
            (_map[Node.InvocationExpression])[Restriction.Arity] = true;
            (_map[Node.InvocationExpression])[Restriction.Name] = true;
            (_map[Node.InvocationExpression])[Restriction.NameRegex] = true;
            (_map[Node.Argument])[Restriction.Reference] = true;
            (_map[Node.PrefixUnaryExpression])[Restriction.Operator] = true;
            (_map[Node.PostfixUnaryExpression])[Restriction.Operator] = true;
        }


        internal bool SupportRuleOnNode(Node node, Restriction ruleType)
        {
            return (_map[node])[ruleType];
        }
    }
}
